package com.yhyvr.api.controller.store;

import com.yhyvr.api.handle.ApiData;
import com.yhyvr.api.service.store.ApiProxyShippingAddressService;
import com.yhyvr.api.tool.ViewFactory;
import com.yhyvr.pojo.req.api.ApiReqBody;
import com.yhyvr.pojo.req.api.ApiReqData;
import com.yhyvr.pojo.req.api.store.address.ApiAddressDefaultSetReq;
import com.yhyvr.pojo.req.api.store.address.ApiAddressSaveUpdateReq;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

/**
 * Created by tech6 on 2016/10/14.
 */

@Controller
public class ApiProxyShippingAddressController{

    @Resource
    private ApiProxyShippingAddressService apiProxyShippingAddressService;


    /**
     * 收货地址列表
     * @param apiReqBodyApiReqData
     */
    @RequestMapping("/api/store/shipping/address")
    public @ResponseBody ModelAndView addressList(@ApiData(tokenValidate = false) ApiReqData<ApiReqBody>apiReqBodyApiReqData){

        return ViewFactory.buildApiJsonpView(apiProxyShippingAddressService.listAddress(apiReqBodyApiReqData),apiReqBodyApiReqData.getCrossDomain());
    }

    /**
     * 新增收货地址
     * @param apiReqBodyApiReqData
     */
    @RequestMapping("/api/store/shipping/address/save")
    public @ResponseBody ModelAndView saveAddress(@ApiData(tokenValidate = false) ApiReqData<ApiAddressSaveUpdateReq>apiReqBodyApiReqData){

        return ViewFactory.buildApiJsonpView(apiProxyShippingAddressService.addAddress(apiReqBodyApiReqData),apiReqBodyApiReqData.getCrossDomain());
    }

    /**
     * 更新收货地址
     * @param apiReqBodyApiReqData
     */
    @RequestMapping("/api/store/shipping/address/update")
    public @ResponseBody ModelAndView updateAddress(@ApiData(tokenValidate = false) ApiReqData<ApiAddressSaveUpdateReq>apiReqBodyApiReqData){

          return ViewFactory.buildApiJsonpView(apiProxyShippingAddressService.updateAddress(apiReqBodyApiReqData),apiReqBodyApiReqData.getCrossDomain());
    }

    /**
     * 获取默认收货地址
     * @param apiReqBodyApiReqData
     */
    @RequestMapping("/api/store/shipping/address/default")
    public @ResponseBody ModelAndView defaultAddress(@ApiData(tokenValidate = false) ApiReqData<ApiReqBody>apiReqBodyApiReqData){

          return ViewFactory.buildApiJsonpView(apiProxyShippingAddressService.defaultAddress(apiReqBodyApiReqData),apiReqBodyApiReqData.getCrossDomain());
    }

    /**
     * 设置默认收货地址
     * @param apiReqBodyApiReqData
     */
    @RequestMapping("/api/store/shipping/address/default/set")
    public @ResponseBody ModelAndView setDefaultAddress(@ApiData(tokenValidate = false) ApiReqData<ApiAddressDefaultSetReq>apiReqBodyApiReqData){

          return ViewFactory.buildApiJsonpView(apiProxyShippingAddressService.setDefaultAddress(apiReqBodyApiReqData),apiReqBodyApiReqData.getCrossDomain());
    }


    /**
     * 删除收货地址
     * @param apiReqBodyApiReqData
     */
    @RequestMapping("/api/store/shipping/address/delete")
    public @ResponseBody ModelAndView deleteDefaultAddress(@ApiData(tokenValidate = false) ApiReqData<ApiAddressDefaultSetReq>apiReqBodyApiReqData){

          return ViewFactory.buildApiJsonpView(apiProxyShippingAddressService.deleteAddress(apiReqBodyApiReqData),apiReqBodyApiReqData.getCrossDomain());
    }
    /**
     * 收货地址详情
     * @param apiReqBodyApiReqData
     */
    @RequestMapping("/api/store/shipping/address/info")
    public @ResponseBody ModelAndView addressInfo(@ApiData(tokenValidate = false) ApiReqData<ApiAddressDefaultSetReq>apiReqBodyApiReqData){

          return ViewFactory.buildApiJsonpView(apiProxyShippingAddressService.addressInfo(apiReqBodyApiReqData),apiReqBodyApiReqData.getCrossDomain());
    }

}
